﻿KISSY.add("js/rv-common", function (S, Auth, UI) {
    S.mix(func, {
        _deletePhoto: function (paramsObj) {
            var confirmDialog = UI.getConfirm(),
                    J = jQuery,
                    popbox = UI.getPopbox();

            Auth.validate(function () {
                confirmDialog.show({
                    header: "Delete Photo",
                    body: "Are you sure you wish to delete this photo? It's a nice one!",
                    confirmBtnText: "Delete",
                    cancelBtnText: "Cancel",
                    confirmCallback: function (paramsObj) {
                        var submitData = paramsObj.submitData,
                            successCallback = paramsObj.successCallback,
                            successCallBackContext = paramsObj.successCallBackContext,
                            successCallBackParams = paramsObj.successCallBackParams;

                        try {
                            J.ajax({
                                url: "/rv/delete/photo",
                                type: "POST",
                                data: submitData,
                                beforeSend: function (jqXHR, settings) {
                                },
                                success: function (data, textStatus, jqXHR) {
                                    var resultCode = FGT.core.constant.jsonResultCode;
                                    if (data.Result === resultCode.SUCCESS) {
                                        if (successCallback) {
                                            successCallback.apply(successCallBackContext || this, successCallBackParams || []);
                                        }
                                    }
                                    else {
                                        popbox.show("Delete failure, please try again later.", 1000);
                                    }
                                },
                                error: function (jqXHR, textStatus, errorThrown) {
                                    popbox.show("Delete failure, please try again later.", 1000);
                                }
                            });
                        }
                        catch (e) {
                            popbox.show("Delete failure, please try again later.", 1000);
                        }
                    },
                    callbackContext: this,
                    confirmCallBackParams: [paramsObj]
                }); //end comfirmDialog.show()
            }, popbox, this); // end Auth
        }, // end _deletePhoto()


        _updatePhoto: function (paramsObj) {
            var J = jQuery,
                submitData = paramsObj.submitData,
                successCallback = paramsObj.successCallback,
                successCallBackContext = paramsObj.successCallBackContext,
                successCallBackParams = paramsObj.successCallBackParams;

            try {
                J.ajax({
                    url: "/rv/update/photo",
                    type: "GET",
                    data: submitData,
                    success: function (data, textStatus, jqXHR) {
                        var resultCode = FGT.core.constant.jsonResultCode;
                        if (data.Result === resultCode.SUCCESS) {
                            if (successCallback) {
                                successCallback.apply(successCallBackContext || this, successCallBackParams || []);
                            }
                        }
                        else {
                            //  popbox.show("Update failure, please try again later.", 1000);
                        }
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        // popbox.show("Update failure, please try again later.", 1000);
                    }
                });
            }
            catch (e) {
                // popbox.show("Update failure, please try again later.", 1000);
            }
        } // end _updatePhoto()

    }); // end mix
    return func;
}, { requires: ["fgt/auth", "fgt/ui"] });